<script lang="ts" setup>
import { gameColumns } from '../game/game.data'
import { useI18n } from '@/hooks/web/useI18n'
import { BasicModal, useModalInner } from '@/components/Modal'
import { updateDeviceGame } from '@/api/vr/device'
import { getGamePageByStatus } from '@/api/vr/game'
import { BasicTable, useTable } from '@/components/Table'
import { useMessage } from '@/hooks/web/useMessage'

defineOptions({ name: 'DeviceGameModal' })
const emit = defineEmits(['success', 'register'])
const { t } = useI18n()
let id = 0
const { createMessage } = useMessage()
const [registerGameModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false })
  id = data.record.id
})

const [registerGameTable, { getRowSelection}] = useTable({
  title: 'VR游戏列表',
  api: getGamePageByStatus,
  columns: gameColumns,
  showTableSetting: true,
  showIndexColumn: false,
  rowSelection: {
    type: 'radio',
  },
  rowKey: 'id',
  beforeFetch: (data)=>{
    var res ={
      pageNo:data.pageNo,
      pageSize:data.pageSize,
      status:0
    }
    return res
  
  }
})

async function handleSubmit(this: any) {
  const a = getRowSelection().selectedRowKeys
  const data = {
    deviceId: id,
    gameId: a?.pop(),

  }
  // console.log(data)
  await updateDeviceGame(data)
  closeModal()
  emit('success')
  createMessage.success(t('common.saveSuccessText'))
}
</script>

<template>
  <BasicModal v-bind="$attrs" title="点播游戏" @register="registerGameModal" @ok="handleSubmit">
    <BasicTable @register="registerGameTable">
    <!-- <template #bodyCell="{ column, record }" /> -->
    </BasicTable>
  </BasicModal>
</template>
